package me.leiusual.sharing.ui.mine

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations.switchMap
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.userrenew.UserRenew
import me.leiusual.sharing.repository.UserRenewRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-08-14
 * description:
 */
class MineRenewViewModel @Inject constructor(
    private val userRenewRepository: UserRenewRepository
) : ViewModel() {

  // 用户续费列表

  private val _userRenewList = MutableLiveData<ParamsUserRenewList>()
  val userRenewList: LiveData<Data<UserRenew>> = switchMap(_userRenewList) {
    userRenewRepository.userRenewList(it.businessType, it.userId).toLiveData()
  }

  fun userRenewList(businessType: String?, userId: Long) {
    _userRenewList.value = ParamsUserRenewList(businessType, userId)
  }

  data class ParamsUserRenewList(val businessType: String?, val userId: Long)
}